<?php

/**
 * Created by XM·Tan.
 * Motto: Who shuts love out, in turn shall be shut out from love.
 * Date: 2020/12/8 17:35
 */
namespace app\api\validate;

use think\Validate;

class User extends Validate {

    protected $rule = [
        'phone_number' => 'require|checkPhone',
    ];

    protected $message = [
        'phone_number' => '手机号码必须',
    ];

    protected $scene = [
        'send_code' => ['phone_number'],
    ];


    /**
     * 自定义 手机号码 校验函数
     * @param $value
     * @param $rule
     * @param array $data
     * @return bool|string
     */
    protected function checkPhone($value, $rule, $data = []) {
        if (!preg_match("/^1[34578]\d{9}$/", $value)) {
            return '您输入的手机号码格式不正确！';
        }
        return true;
    }

}